/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.turingtechnologies.materialscrollbardemo.customview;

import com.turingtechnologies.materialscrollbardemo.ResourceTable;
import com.turingtechnologies.materialscrollbardemo.adapters.ViewCreateHelper;
import com.turingtechnologies.materialscrollbardemo.slice.MultiFragmentActivitySlice;
import ohos.agp.components.*;

import java.util.List;

public class TestPagerProvider extends PageSliderProvider {
    private List<DataItem> list;
    private MultiFragmentActivitySlice slice;

    /**
     * TestPagerProvider build
     *
     * @param aList list
     * @param aSlice slice
     */
    public TestPagerProvider(List<DataItem> aList, MultiFragmentActivitySlice aSlice) {
        this.slice = aSlice;
        this.list = aList;
    }

    private int[] resLayout = new int[]{
        ResourceTable.Layout_page_multi
    };

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {
        DependentLayout label = new DependentLayout(null);
        ViewCreateHelper viewCreateHelper = new ViewCreateHelper(slice);
        label.addComponent(viewCreateHelper.createView(resLayout[0], 2));
        label.setLayoutConfig(
                new StackLayout.LayoutConfig(
                        ComponentContainer.LayoutConfig.MATCH_PARENT,
                        ComponentContainer.LayoutConfig.MATCH_PARENT
                ));

        componentContainer.addComponent(label);
        return label;
    }

    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
        componentContainer.removeComponent((Component) o);
    }

    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return true;
    }

    // 数据实体类
    public static class DataItem {
        public DataItem() {
        }
    }
}